// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { GameEvent } from "./GameEvent";
import PlayerInfo from "./PlayerInfo";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PlayerInfoView extends cc.Component {

    

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.getComponent(cc.Label).string = PlayerInfo.ins.money.toFixed(2);
        cc.game.on(GameEvent.PLAYER_MONEY_CHANGE, this.onMoneyChange,this)
    }

    onMoneyChange() {
        this.node.getComponent(cc.Label).string = PlayerInfo.ins.money.toFixed(2);
    }

    protected onDestroy(): void {
        cc.game.off(GameEvent.PLAYER_MONEY_CHANGE, this.onMoneyChange,this)
    }

    start () {

    }

    // update (dt) {}
}
